/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import db.DataBase;

/**
 *
 * @author Thiago Parra
 */
public class Escrow {

    public static int timestamp = 0;

    public static boolean reserveProduct(int id, int quantity) {
        if (DataBase.subInf(String.valueOf(id), quantity) && DataBase.subVal(String.valueOf(id), quantity)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean reservenegativeProduct(int id, int quantity){
        if (DataBase.addVal(String.valueOf(id), quantity) && DataBase.addSup(String.valueOf(id), quantity)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean replaceReservedProduct(int id, int quantity) {
        if (DataBase.addInf(String.valueOf(id), quantity) && DataBase.addVal(String.valueOf(id), quantity)) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean sellReservedProduct(int id, int quantity) {
        if (DataBase.subSup(String.valueOf(id), quantity)) {
            timestamp++;
            return true;
        } else {
            return false;
        }
    }

        public static boolean sellReservednegativeProduct(int id, int quantity) {
        if (DataBase.addInf(String.valueOf(id), quantity)) {
            timestamp++;
            return true;
        } else {
            return false;
        }
    }

    public static String journalEscrow(){
        String transation = "TS" + timestamp;
        timestamp++;
        return transation;
    }
}
